extends Node2D


@onready var sprite: Sprite2D = $Sprite2D


var sequence: BehaviorTreeSequence
var done: bool


func _ready():
    var node1 := TestMoveNode.new()
    node1.display_name = "move_node1"
    node1.control_node = sprite
    node1.direction = Vector2.RIGHT
    node1.target = Vector2(250.0, 0.0)

    var node2 := TestMoveNode.new()
    node2.display_name = "move_node2"
    node2.control_node = sprite
    node2.direction = Vector2.DOWN
    node2.target = Vector2(250.0, 250.0)

    sequence = BehaviorTreeSequence.new()
    sequence.add_child(node1)
    sequence.add_child(node2)

    sequence._on_enter()


func _process(delta: float):
    if done:
        return
    var state := sequence._tick(delta)
    if state == BehaviorTreeNode.NodeState.SUCCESS:
        sequence._on_exit()
        done = true
    elif state == BehaviorTreeNode.NodeState.FAILURE:
        sequence._on_exit()
        done = true